import {createRouter, createWebHistory} from 'vue-router'


const routes=[
    {
        path:'/',
        redirect: '/index/shouye',  // 重定向:重新指向其它path,会改变网址

    },
    {
        path:'/index',
        component:()=>import('../pages/index/index.vue'),
        children:[
            {
                path:'/index/shouye',
                component:()=>import('../pages/shouye/index.vue')
            },
            // 产品管理
            {
                path:'/index/product',
                component:()=>import('../pages/product/product.vue')
            },
            {
                path:'/index/classify',
                component:()=>import('../pages/product/classify.vue')
            },
            {
                path:'/index/grouping',
                component:()=>import('../pages/product/grouping.vue')
            },
            {
                path:'/index/comment',
                component:()=>import('../pages/product/comment.vue')
            },
            {
                path:'/index/Specifications',
                component:()=>import('../pages/product/Specifications.vue')
            },
            //门店管理  
            {
                path:'/index/Notice',
                component:()=>import('../pages/store/Notice.vue')
            },
            {
                path:'/index/Self',
                component:()=>import('../pages/store/Self.vue')
            },
            {
                path:'/index/freight',
                component:()=>import('../pages/store/freight.vue')
            },
            {
                path:'/index/swiper',
                component:()=>import('../pages/store/swiper.vue')
            },
            {
                path:'/index/Hotsearch',
                component:()=>import('../pages/store/Hotsearch.vue')
            },
            //会员管理
            {
                path:'/index/vip',
                component:()=>import('../pages/vip/vip.vue')
            },
            //订单管理
            {
                path:'/index/order',
                component:()=>import('../pages/order/order.vue')
            }, 
            //系统管理
            {
                path:'/index/address',
                component:()=>import('../pages/system/address.vue')
            },
            {
                path:'/index/administrators',
                component:()=>import('../pages/system/administrators.vue')
            },
            {
                path:'/index/role',
                component:()=>import('../pages/system/role.vue')
            },
            {
                path:'/index/menu',
                component:()=>import('../pages/system/menu.vue')
            },
            {
                path:'/index/timing',
                component:()=>import('../pages/system/timing.vue')
            },
            {
                path:'/index/parameter',
                component:()=>import('../pages/system/parameter.vue')
            },
            {
                path:'/index/journal',
                component:()=>import('../pages/system/journal.vue')
            },
        ]
    },
    
    {
        path:'/login',
        component:()=>import('../pages/login/login.vue')
    },
    {
        path:'/404',
        component:()=>import('../pages/404/index.vue')
    },
]

const router=createRouter({
    history:createWebHistory(),
    routes
})

//白名单
//includes 和 indexof 的区别
//includes 判断数组中是否存在要查找的值 不存在返回false 否则为true 能判断nan
//indexof 判断数组中是否存在要查找的值 -1 否则为0  不能判断nan
const whilteList=['/login','/404',]

router.beforeEach((to,from,next)=>{
    if(whilteList.includes(to.path)) return next()
    if(!localStorage.getItem('token')){

        return next('/login')
    }
    next()
})

export default router